/**
 * 
 */
package org.insia.smartposse.xfire.service;

import java.util.ArrayList;
import java.util.List;

import org.insia.smartposse.config.DAOFactory;
import org.insia.smartposse.metier.Freelance;
import org.insia.smartposse.metier.FreelanceAlert;
import org.insia.smartposse.metier.FreelancePortfolio;
import org.insia.smartposse.metier.FreelanceSkill;
import org.insia.smartposse.metier.Project;
import org.insia.smartposse.metier.webservice.LightFreelance;
import org.insia.smartposse.metier.webservice.LightFreelanceAlert;
import org.insia.smartposse.metier.webservice.LightFreelancePortfolio;
import org.insia.smartposse.metier.webservice.LightFreelanceSkill;
import org.insia.smartposse.metier.webservice.LightProject;
import org.insia.smartposse.xfire.iservice.IFreelanceService;

/**
 * @author raguerri
 * @since 18 avr. 07
 * @version 0.0.1
 * 
 */
public class FreelanceService implements IFreelanceService {

	/* (non-Javadoc)
	 * @see org.insia.smartposse.xfire.iservice.IFreelance#getLFreelance(long)
	 */
	public LightFreelance get(long id) {
		LightFreelance lflance = null;
		try {
			Freelance flance = DAOFactory.getFreelanceDAO().get(id);
			lflance = flance.setLight();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return lflance;
	}

	/* (non-Javadoc)
	 * @see org.insia.smartposse.xfire.iservice.IFreelanceService#getFreelanceSkill(long)
	 */
	public LightFreelanceSkill getFreelanceSkill(long id) {
		LightFreelanceSkill lfskill = null;
		try {
			FreelanceSkill fskill = DAOFactory.getFreelanceSkillDAO().get(id);
			lfskill = fskill.setLight();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return lfskill;
	}

	/* (non-Javadoc)
	 * @see org.insia.smartposse.xfire.iservice.IFreelanceService#getFreelanceAlert(long)
	 */
	public LightFreelanceAlert getFreelanceAlert(long id) {
		LightFreelanceAlert lfalert = null;
		try {
			FreelanceAlert falert = DAOFactory.getFreelanceAlertDAO().get(id);
			lfalert = falert.setLight();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return lfalert;
	}

	/* (non-Javadoc)
	 * @see org.insia.smartposse.xfire.iservice.IFreelanceService#getFreelancePortfolio(long)
	 */
	public LightFreelancePortfolio getFreelancePortfolio(long id) {
		LightFreelancePortfolio lfport = null;
		try {
			FreelancePortfolio fport = DAOFactory.getFreelancePortfolioDAO().get(id);
			lfport = fport.setLight();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return lfport;
	}
	
	/* (non-Javadoc)
	 * @see org.insia.smartposse.xfire.iservice.IFreelanceService#getProjects(long)
	 */
	public List<LightProject> getProjects(long freelance_id) {
		List<LightProject> lproj = new ArrayList<LightProject>();
		try {
			List<Project> projs = DAOFactory.getProjectDAO().getFrom(freelance_id);
			for (Project project : projs) {
				lproj.add(project.setLight());
			}
		}catch (Exception e) {
			e.printStackTrace();
		}
		return lproj;
	}

	public LightFreelance set(LightFreelance freelance) {
		LightFreelance free = null;
		try {
			free = DAOFactory.getFreelanceDAO().createLightFreelance(freelance);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return free;
	}

	/* (non-Javadoc)
	 * @see org.insia.smartposse.xfire.iservice.IFreelanceService#createLightFreelance(org.insia.smartposse.metier.webservice.LightFreelance)
	 */
	public LightFreelance createLightFreelance(LightFreelance freelance) {
		return DAOFactory.getFreelanceDAO().createLightFreelance(freelance);
	}

	/* (non-Javadoc)
	 * @see org.insia.smartposse.xfire.iservice.IFreelanceService#createLightFreelanceAlert(org.insia.smartposse.metier.webservice.LightFreelanceAlert)
	 */
	public LightFreelanceAlert createLightFreelanceAlert(LightFreelanceAlert lfalert) {
		return DAOFactory.getFreelanceAlertDAO().createLightFreelanceAlert(lfalert);
	}

	/* (non-Javadoc)
	 * @see org.insia.smartposse.xfire.iservice.IFreelanceService#createLightFreelanceAlert(java.util.List)
	 */
	public List<LightFreelanceAlert> createLightFreelanceAlert(List<LightFreelanceAlert> llfalert) {
		return DAOFactory.getFreelanceAlertDAO().createLightFreelanceAlert(llfalert);
	}

	/* (non-Javadoc)
	 * @see org.insia.smartposse.xfire.iservice.IFreelanceService#createLightFreelancePortfolio(org.insia.smartposse.metier.webservice.LightFreelancePortfolio)
	 */
	public LightFreelancePortfolio createLightFreelancePortfolio(LightFreelancePortfolio lfport) {
		return DAOFactory.getFreelancePortfolioDAO().createLightFreelancePortfolio(lfport);
	}

	/* (non-Javadoc)
	 * @see org.insia.smartposse.xfire.iservice.IFreelanceService#createLightFreelancePortfolio(java.util.List)
	 */
	public List<LightFreelancePortfolio> createLightFreelancePortfolio(List<LightFreelancePortfolio> llfport) {
		return DAOFactory.getFreelancePortfolioDAO().createLightFreelancePortfolio(llfport);
	}

	/* (non-Javadoc)
	 * @see org.insia.smartposse.xfire.iservice.IFreelanceService#createLightFreelanceSkill(org.insia.smartposse.metier.webservice.LightFreelanceSkill)
	 */
	public LightFreelanceSkill createLightFreelanceSkill(LightFreelanceSkill lskill) {
		return DAOFactory.getFreelanceSkillDAO().createLightFreelanceSkill(lskill);
	}

	/* (non-Javadoc)
	 * @see org.insia.smartposse.xfire.iservice.IFreelanceService#createLightFreelanceSkill(java.util.List)
	 */
	public List<LightFreelanceSkill> createLightFreelanceSkill(List<LightFreelanceSkill> llfskill) {
		return DAOFactory.getFreelanceSkillDAO().createLightFreelanceSkill(llfskill);
	}

	/* (non-Javadoc)
	 * @see org.insia.smartposse.xfire.iservice.IFreelanceService#updateLightFreelance(org.insia.smartposse.metier.webservice.LightFreelance)
	 */
	public LightFreelance updateLightFreelance(LightFreelance freelance) {
		return DAOFactory.getFreelanceDAO().updateLightFreelance(freelance);
	}

	/* (non-Javadoc)
	 * @see org.insia.smartposse.xfire.iservice.IFreelanceService#updateLightFreelanceAlert(org.insia.smartposse.metier.webservice.LightFreelanceAlert)
	 */
	public LightFreelanceAlert updateLightFreelanceAlert(LightFreelanceAlert lfalert) {
		return DAOFactory.getFreelanceAlertDAO().updateLightFreelanceAlert(lfalert);
	}

	/* (non-Javadoc)
	 * @see org.insia.smartposse.xfire.iservice.IFreelanceService#updateLightFreelanceAlert(java.util.List)
	 */
	public List<LightFreelanceAlert> updateLightFreelanceAlert(List<LightFreelanceAlert> llfalert) {
		return DAOFactory.getFreelanceAlertDAO().updateLightFreelanceAlert(llfalert);
	}

	/* (non-Javadoc)
	 * @see org.insia.smartposse.xfire.iservice.IFreelanceService#updateLightFreelancePortfolio(org.insia.smartposse.metier.webservice.LightFreelancePortfolio)
	 */
	public LightFreelancePortfolio updateLightFreelancePortfolio(LightFreelancePortfolio lfport) {
		return DAOFactory.getFreelancePortfolioDAO().updateLightFreelancePortfolio(lfport);
	}

	/* (non-Javadoc)
	 * @see org.insia.smartposse.xfire.iservice.IFreelanceService#updateLightFreelancePortfolio(java.util.List)
	 */
	public List<LightFreelancePortfolio> updateLightFreelancePortfolio(List<LightFreelancePortfolio> llfport) {
		return DAOFactory.getFreelancePortfolioDAO().updateLightFreelancePortfolio(llfport);
	}

	/* (non-Javadoc)
	 * @see org.insia.smartposse.xfire.iservice.IFreelanceService#updateLightFreelanceSkill(org.insia.smartposse.metier.webservice.LightFreelanceSkill)
	 */
	public LightFreelanceSkill updateLightFreelanceSkill(LightFreelanceSkill lskill) {
		return DAOFactory.getFreelanceSkillDAO().updateLightFreelanceSkill(lskill);
	}

	/* (non-Javadoc)
	 * @see org.insia.smartposse.xfire.iservice.IFreelanceService#updateLightFreelanceSkill(java.util.List)
	 */
	public List<LightFreelanceSkill> updateLightFreelanceSkill(List<LightFreelanceSkill> llfskill) {
		return DAOFactory.getFreelanceSkillDAO().updateLightFreelanceSkill(llfskill);
	}
}
